package com.ai.wx.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ai.core.dao.BaseDaoI;
import com.ai.wx.entity.History;
import com.ai.wx.service.HistoryService;

@Service
public class HistoryServiceImpl implements HistoryService {
	@Autowired
	private BaseDaoI<History> historyDao;

	@Override
	public List<History> getHistorysByOpenid(String openId) {
		String hql = "from History h where h.openid=:openId order by h.recordDate desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("openId", openId);
		return historyDao.find(hql, params,1,6);
	}

	@Override
	public void saveHistory(String openId, String mobileNumber, String promotionCode) {
		History history = new History();
		history.setOpenid(openId);
		history.setPhone(mobileNumber);
		history.setCode(promotionCode);
		history.setRecordDate(new Date());
		historyDao.save(history);
	}

}
